package com.cxhc.app.api;

import javax.servlet.http.HttpServletResponse;

import com.cxhc.common.utils.poi.ExcelUtil;
import com.cxhc.system.domain.app.CmApartmentInfo;
import com.cxhc.system.service.app.ICmApartmentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;
import com.cxhc.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 公寓信息Controller
 * 
 * @author Dhq
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/api/apartment")
public class CmApartmentInfoController extends BaseController
{
    @Autowired
    private ICmApartmentInfoService cmApartmentInfoService;

    /**
     * 查询公寓信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmApartmentInfo cmApartmentInfo)
    {
        startPage();
        List<CmApartmentInfo> list = cmApartmentInfoService.selectCmApartmentInfoList(cmApartmentInfo);
        return getDataTable(list);
    }

    /**
     * 导出公寓信息列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmApartmentInfo cmApartmentInfo)
    {
        List<CmApartmentInfo> list = cmApartmentInfoService.selectCmApartmentInfoList(cmApartmentInfo);
        ExcelUtil<CmApartmentInfo> util = new ExcelUtil<CmApartmentInfo>(CmApartmentInfo.class);
        util.exportExcel(response, list, "公寓信息数据");
    }

    /**
     * 获取公寓信息详细信息
     */
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmApartmentInfoService.selectCmApartmentInfoById(id));
    }

    /**
     * 新增公寓信息
     */
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody CmApartmentInfo cmApartmentInfo)
    {
        return toAjax(cmApartmentInfoService.insertCmApartmentInfo(cmApartmentInfo));
    }

    /**
     * 修改公寓信息
     */
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody CmApartmentInfo cmApartmentInfo)
    {
        return toAjax(cmApartmentInfoService.updateCmApartmentInfo(cmApartmentInfo));
    }

    /**
     * 删除公寓信息
     */
    @GetMapping(value = "/delete/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(cmApartmentInfoService.deleteCmApartmentInfoById(id));
    }
}
